<?php
class AdminController extends AdminBaseController  {
	public function maintop(){
		$topColumn = HttpServerManager::getFunctionServer()->topColumnList();
		foreach ($topColumn as $k=>$v){
			$topColumn[$k]['title'] = Common::_t($v['mark']);
		}
		$data['tmpColumn'] = $topColumn;
		return $data;
	}
	public function leftJs(){
		$functionServer  = HttpServerManager::getFunctionServer();
		$column = $functionServer->topColumnList();
		$column1 = array();
		$column2 = array();
		foreach ($column as $v){
			$column1[$v['id']] = $functionServer->topColumnList($v['id']);
			foreach ($column1[$v['id']] as $v1 ){
				$column2[$v1['id']] = $functionServer->getListByFatherId($v1['id']);
			}
		}
		
		$data['column'] = $column;
		$data['column1'] = $column1;
		$data['column2'] = $column2;
		return $data;
	}
	public function left(){
		$functionServer  = HttpServerManager::getFunctionServer();
		$column = $functionServer->topColumnList();
		$data['default_left_menu']='user';
		if(!empty($column)){
			$data['default_left_menu'] = $column[0]['mark'];
		}
		
		$admin_type = $_SESSION['admin']['admin_type'];
		$admin_name = $_SESSION['admin']['name'];

		if($admin_type == ADMIN_TYPE_EMPLOYEE){
			$employee_id = $_SESSION['admin']['employee_id'];
			$employee_info = HttpDaoManager::getEmployeesDao()->get($employee_id);
			$admin_name = $employee_info['name'];
		}
		
		if($admin_type == ADMIN_TYPE_TEACHER){
			$teacher_id = $_SESSION['admin']['teacher_id'];
			$teacher_info = HttpDaoManager::getTeacherDao()->get($teacher_id);
			$admin_name = $teacher_info['name'];
			$data['teacher_star'] = $teacher_info['real_education_experience'];
		}		
		
		$data['admin_name'] = $admin_name;
		return $data;
	}
	public function  lists()	{
		$data = array();
		
		$data = HttpServerManager::getAdminServer()->pagingBySearch($_GET);
		$data['admin_type']=Common::_t('admin_type');
		
		$eo_admin_type_list = HttpDaoManager::getAdminGroupDao()->getList1();
		$data['eo_admin_type'] = Common::fetchPairOfList('id', 'name', $eo_admin_type_list);

		$data['department'] = Common::_t('department');
		$data['status'] = Common::_t('status');
		
		$data['teacher_dept'] = Common::_t('teacher_dept');			
		$data['default_language'] = Common::_t('default_language');			
		
		$data['page_status_option']= $data['status'];
		$data['page_department_option']= $data['department'];
		$data['page_admin_group_option']= $data['eo_admin_type'];
		$data['page_admin_type_option']= $data['admin_type'];
		
		return $data;
	}
	public function delete(){
		HttpServerManager::getAdminServer()->deleteBatchByid($_GET['id']);
		ClassManager::getToos()->msgbox(Common::_t('data_del_success'));
	}
	public function add(){
		if (!empty($_GET['id'])){
			$tmp = HttpDaoManager::getAdminDao()->getById($_GET['id']);
		}
		$tmp['functoinList'] = HttpDaoManager::getAdminGroupDao()->getList1();
		$tmp['departmentList'] = Common::_t('department');
		
		$employees = array();
		$employeesDao = HttpDaoManager::getEmployeesDao();
		foreach ($tmp['departmentList'] as $k=>$v){
			$employees[$k] = $employeesDao->getListByDepartment($k);
		}
		
		$defaultLanguage = Common::_t('default_language');
		$defaultLanguageOption = page_modifier_options($defaultLanguage,getStr($tmp, 'default_language'));
		$tmp['defaultLanguageOption'] = $defaultLanguageOption;
		$tmp['id'] = Common::getGetStrValue('id');
		$tmp['employees'] = $employees;
		$tmp['teacher'] = HttpDaoManager::getTeacherDao()->searchList();
		
		$funduser_pair = array();
		$funduser_list =  HttpDaoManager::getFunduserDao()->searchList();
		foreach($funduser_list as $key=>$value){
			$funduser_pair[$value['id']] = $value['serial_number'].'-'.$value['name'];
		}
		//页面标签使用
		$tmp['page_admintype_radios']=Common::_t('admin_type');
		
		$tmp['page_funduser_options'] =   page_modifier_options($funduser_pair,common::getStrValue($tmp, 'fund_user_id'));
		
		return $tmp ;
	}
	public function subAdd(){
		$tmp =HttpServerManager::getAdminServer()->add($_POST);
		$error_msg = Common::_t('eror_msgbox');
		if ($tmp===true){
			ClassManager::getToos()->msgbox(Common::_t('data_insert_success'));
		}
		else{
			if($tmp==ERROR_CODE_ONE){
				ClassManager::getToos()->msgbox($error_msg[ERROR_CODE_ONE]);
			}
			if($tmp==ERROR_CODE_TWO){
				ClassManager::getToos()->msgbox($error_msg[ERROR_CODE_TWO]);
			}
			if($tmp==ERROR_CODE_THREE){
				ClassManager::getToos()->msgbox($error_msg[ERROR_CODE_THREE]);
			}
		}
	}
	public function subUpdate(){
		HttpServerManager::getAdminServer()->update($_POST, $_POST['id']);
		ClassManager::getToos()->msgbox(Common::_t('data_edit_success'),'admin_lists.html');
	}
	public function login(){
		if (!empty($_POST['sub']))		{
			$admin = HttpServerManager::getAdminServer();
			$login = $admin->logion($_POST['name'],$_POST['password']);
			$error_msgbox = Common::_t('eror_login_msgbox');
			if ($login==true){
				header("Location: admin_home.html");
			}
			else {
				ClassManager::getToos()->msgbox($error_msgbox[ERROR_CODE_ONE]);
			}
		}
	}
	public function quit(){
		$admin=HttpServerManager::getAdminServer();
		$admin->quit();
		header("Location: login.html");
	}
	public function subUpdatePassword(){
		$error_msgbox = Common::_t('eror_login_msgbox');
		if(empty($_POST['old_password'])){
			ClassManager::getToos()->msgbox($error_msgbox[ERROR_CODE_SIX]);
		}
		$admin_info = HttpDaoManager::getAdminDao()->getById($_SESSION['admin']['id']);
		if(!empty($admin_info)){
			$admin_password = $admin_info['password'];
			if(md5($_POST['old_password'])!=$admin_password){
				ClassManager::getToos()->msgbox($error_msgbox[ERROR_CODE_FIVE]);
			}
		}
		
		if ($_POST['password']!=$_POST['qrpassword']){
			ClassManager::getToos()->msgbox($error_msgbox[ERROR_CODE_TWO]);
		}
		$tmp  = HttpServerManager::getAdminServer()->updatePassword($_POST['password']);
		if ($tmp===true){
			ClassManager::getToos()->msgbox($error_msgbox[ERROR_CODE_THREE]);
		}
		else{
			ClassManager::getToos()->msgbox($error_msgbox[ERROR_CODE_FOUR]);
		}
	}
}
?>